package jdbc.test;

import cn.myschool.java79.util.DBUtil;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
//元信息
public class MEtataData {
    public static void main(String[] args) throws SQLException {
        Connection connection = DBUtil.getConnection();
        DatabaseMetaData metaData = connection.getMetaData();
        System.out.println(metaData.getDatabaseProductName());
        System.out.println(metaData.getDatabaseProductVersion());
        System.out.println("索引最多的列数:"+metaData.getMaxColumnsInIndex());
        PreparedStatement ps=connection.prepareStatement("select * from s_student");
        ResultSet rs = ps.executeQuery();
        ResultSetMetaData rm = rs.getMetaData();
        System.out.println("共有"+rm.getColumnCount()+"列");
        for(int i=1;i<=rm.getColumnCount();i++){
            System.out.println("第"+i+"列："+rm.getColumnLabel(i)+",类型："+rm.getColumnTypeName(i)+",对应的java类型:"+rm.getColumnClassName(i));
        }
        DBUtil.close(connection);
    }
}
